#ifndef GTRANSLATE_H_INCLUDED
#define GTRANSLATE_H_INCLUDED

#include "../config.h"
#include "defs.h"
/* gtrans - Translation helped by Google
 * Copyright (C) 2011 Nagy Attila
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <string>
#include <map>
#include <gtkmm.h>
#ifdef HAVE_LIBSOUP_GNOME
#include <libsoup/soup-gnome.h>
#else
#include <libsoup/soup.h>
#endif
#include <libnotify/notify.h>
#include <libnotify/notification.h>
#include <json-glib/json-glib.h>
#include <json-glib/json-gobject.h>
#include <giomm/settings.h>
#include <gst/gst.h>

#ifndef ICON_PATH
#define ICON_PATH "./"
#endif
#define ICON_PATH_LOGO PIXMAPDIR "/gtrans.png"
#define ICON_PATH_ON   PIXMAPDIR "/gtrans_small.png"
#define ICON_PATH_OFF  PIXMAPDIR "/gtrans_small_off.png"
#define ICON_PATH_WARN PIXMAPDIR "/gtrans_warn.png"

#define CLIPBOARD_TARGET "UTF8_STRING"

#define GOOGLE_URI "https:/\
/www.googleapis.com/language/translate/v2?"

#define GOOGLE_SPEAKER_URI "http:/\
/translate.google.com/translate_tts?"
#define GOOGLE_SPEAKER_USER_AGENT "Mozilla/5.0 (X11; U; Linux i686; hu-HU; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13"
#define MAX_GOOGLE_SPEAKER_LENGTH 100

class GTrans
{
public:
    GTrans ();
    ~GTrans ();
    static void trim (std::string& str);

protected:
    void on_status_icon_popup_menu (guint button, guint32 activate_time);
    void on_status_icon_activate ();
    void on_enabled_menu_item_activate ();
    void on_preferences_menu_item_activate ();
    void on_about_menu_item_activate ();
    void on_exit_menu_item_activate ();
    void on_clipboard_owner_change (GdkEventOwnerChange *event);
    void on_clipboard_received (const Gtk::SelectionData& selection_data);
    void on_settings_changed (const Glib::ustring& key);
    void on_conf_enabled_changed ();
    void on_conf_source_language_changed ();
    void on_conf_target_language_changed ();
    void translate_google ();
    static void on_translated_google (SoupSession *session, SoupMessage *msg, gpointer user_data);
    static void iterate_translations (JsonArray *array, guint index_, JsonNode *element_node, gpointer user_data);
    void show_translated_text ();
    void speak ();
    void speak (std::string& text, Glib::ustring lang);
    static gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer pipeline);
    void play_uri (const char *uri);
    Glib::ustring get_source_language ();
    Glib::ustring get_target_language ();
    void set_tooltip_text ();

    static void handle_log (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data);
    static void error_info (const char *message, char *info);

    languages_map languages;

    Glib::RefPtr<Gtk::StatusIcon> m_refStatusIcon;
    Glib::RefPtr<Gtk::UIManager> m_refUIManager;
    Glib::RefPtr<Gtk::ActionGroup> m_refActionGroup;
    NotifyNotification *m_notification;
    Glib::RefPtr<Gio::Settings> m_refSettings;

    std::string source_text_act;
    std::string target_text_act;
    Glib::ustring source_lang_act;
    Glib::ustring target_lang_act;
    bool source_lang_listen;
    bool target_lang_listen;
    GstElement *pipeline;
};

#endif // GTRANSLATE_H_INCLUDED

